package com.example;

import lombok.Cleanup;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 *
 *
 */
public class App 
{
    public static void main( String[] args ) throws FileNotFoundException {

//        try(FileOutputStream fileOutput = new FileOutputStream("xx.txt", true);
//            FileInputStream fileInputStream = new FileInputStream("text.txt")) {
//            int len;
//            byte[] buf = new byte[1024];
//            while ((len = fileInputStream.read(buf)) != -1) {
//                fileOutput.write(buf, 0, len);
//            }
//
//        }
//        catch (IOException e) {
//            throw new RuntimeException(e);
//        }

//        try (FileReader fileReader = new FileReader("text.txt")) {
//            int i;
//            while ((i = fileReader.read()) != -1) {
//                System.out.print((char) i);
//            }
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }

//        try (FileWriter fileWriter = new FileWriter("text.txt",true)) {
//            fileWriter.write("\n这是fileWrite添加的字句");
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }

        try (FileWriter fileWriter = new FileWriter("xxx.txt",true);
             FileReader fileReader = new FileReader("text.txt")) {
            int len;
            char[] buf = new char[1024];
            while ((len = fileReader.read(buf)) != -1) {
                fileWriter.write(buf, 0, len);
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }

}
